package org.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class WelcomeView extends Activity {
	
	private static final int ACTIVITY_CREATE = 0;
	private Button tripButton;
	private Button contactsButton;
	private Button btnProfile;
	private Button btnQuit;
	private int userId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		
		Bundle extras = getIntent().getExtras();
		
		if (extras != null) {
			userId = extras.getInt("userId");
			
			tripButton = (Button) findViewById(R.id.tripsButton);
			contactsButton = (Button) findViewById(R.id.contactsButton);
			btnProfile = (Button) findViewById(R.id.btnProfile);
			btnQuit = (Button) findViewById(R.id.btnQuit);
			
			tripButton.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					goToTrips();
				}
			});
		
			contactsButton.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					goToContacts();
				}
			});
	
			btnProfile.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					goToProfile();
				}
			});
		
			btnQuit.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					goToLogin();
				}
			});
		}
	}

	protected void goToLogin() {
		Intent i = new Intent(this, LoginView.class);
		startActivityForResult(i, ACTIVITY_CREATE);
	}

	protected void goToProfile() {
		Intent i = new Intent(this, ProfileInfoView.class);
		i.putExtra("userId", userId);
		startActivityForResult(i, ACTIVITY_CREATE);
	}

	private void goToTrips() {
		Intent i = new Intent(this, TripListView.class);
		i.putExtra("userId", userId);
		startActivityForResult(i, ACTIVITY_CREATE);

	}
	
	private void goToContacts() {
		
		Intent i = new Intent(this, ContactListView.class);
		i.putExtra("userId", userId);
		startActivityForResult(i, ACTIVITY_CREATE);
	}
}
